#!/bin/bash

# This script allows to gracefully start MCS

# prevent nodes using shared storage manager from stepping on each other when initializing
# flock will open up an exclusive file lock to run atomic operations
exec {fd_lock}>@ENGINE_DATADIR@/storagemanager/storagemanager-lock
flock -n "$fd_lock" || exit 0

# pass in arg of 1 to start DBRM_Worker1
/bin/systemctl start mcs-workernode@1.service
/bin/systemctl start mcs-controllernode
/bin/systemctl start mcs-primproc
/bin/systemctl start mcs-writeengineserver
/bin/systemctl start mcs-dmlproc
/bin/systemctl start mcs-ddlproc
su -s /bin/sh -c '@ENGINE_BINDIR@/dbbuilder 7' @DEFAULT_USER@ 1> @ENGINE_LOGDIR@/install/dbbuilder.log

flock -u "$fd_lock"

exit 0
